package com.ruoyi.project.xcx.myhome.category.api;

import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.xcx.myhome.category.service.IXcxMyhomeCategoryService;
import com.ruoyi.project.xcx.user.domain.XcxUser;
import com.ruoyi.project.xcx.util.TokenUserUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 分类控制器（小程序）
 */
@RestController
@RequestMapping("/wx/category")
@Slf4j
public class CategoryConroller {
    @Autowired
    private IXcxMyhomeCategoryService xcxMyhomeCategoryService;

    /**
     * 查询用户所有的列表
     * @return
     */
    @GetMapping("/listCategory")
    public AjaxResult listCategory(){
        XcxUser user = TokenUserUtil.getUser();
        return AjaxResult.success(xcxMyhomeCategoryService.listCategory(user));
    }
    /**
     * 删除分类
     */
    @GetMapping("deleteCategory")
    @Log(title = "小程序删除分类", businessType = BusinessType.DELETE)
    public AjaxResult deleteCategory(Long id){
        XcxUser user = TokenUserUtil.getUser();
        xcxMyhomeCategoryService.deleteCategory(id, user);
        return AjaxResult.success();
    }

}
